<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="所属商家" prop="merId">
        <el-select v-model="queryParams.merId" placeholder="请选择小区" style="width: 150px;" size="mini">
          <el-option v-for="mer in merListOptions"
                     :key="mer.id"
                     :label="mer.shopName"
                     :value="mer.id"/>
        </el-select>
      </el-form-item>

      <el-form-item label="查询时间" prop="propertyName">
        <el-date-picker v-model="dateRange" size="mini" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
      </el-form-item>

      <el-form-item label="订单状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择订单状态" style="width: 150px;" size="mini">
          <el-option label="未支付" :value="0" />
          <el-option label="待支付" :value="1" />
          <el-option label="已支付" :value="2" />
          <el-option label="已核销" :value="3" />
          <el-option label="已评价" :value="4" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col" >
        <div class="card-panel" style="background-color: #67C23A;">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="today" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description" >
            <div class="card-panel-text">订单数</div>
            <count-to :start-val="0" :end-val="total" :duration="2600" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" style="background-color: #E6A23C;">
          <div class="card-panel-icon-wrapper icon-message">
            <svg-icon icon-class="ic-yesterday" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">总交易金额</div>
            <count-to :start-val="0" :end-val="otherDate.totalPrice" :decimals="2" :duration="3000" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" style="background-color: #E6A23C;">
          <div class="card-panel-icon-wrapper icon-message">
            <svg-icon icon-class="ic-yesterday" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">总手续费</div>
            <count-to :start-val="0" :end-val="otherDate.merFee" :decimals="2" :duration="3000" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" style="background-color: #F56C6C;">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="seven" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">总结算金额</div>
            <count-to :start-val="0" :end-val="otherDate.merSettlement" :decimals="2" :duration="3000" class="card-panel-num" />
          </div>
        </div>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="45" align="center" />
      <el-table-column label="订单号" align="center" prop="orderNo" />
      <el-table-column label="所属商家" align="center" prop="shopName" />
      <el-table-column label="用户昵称" align="center" prop="realName" />
      <el-table-column label="用户电话" align="center" prop="userPhone" />
      <el-table-column label="订单总价" align="center" prop="totalPrice" />
      <el-table-column label="支付金额" align="center" prop="payPrice" />
      <el-table-column label="支付时间" align="center" prop="payTime" />
      <el-table-column label="平台手续费" align="center" prop="merFee" />
      <el-table-column label="结算金额" align="center" prop="merSettlement" />
      <el-table-column label="订单状态" align="center" prop="status">
        <template slot-scope="scope">
          <div>
            <!-- 订单状态 0 - 未支付   1 - 待支付  2 - 已支付  3 - 已核销 4 - 已评价
            5 - 订单取消  6 - 已申请退货  7 - 同意退货  8 - 退货完成 9 - 拒绝退货 10 - 已完成 -->
            <el-tag v-if="scope.row.status === 0" style="cursor: pointer" :type="'info'">未支付</el-tag>
            <el-tag v-if="scope.row.status === 1" style="cursor: pointer" :type="''">待支付</el-tag>
            <el-tag v-if="scope.row.status === 2" style="cursor: pointer" :type="'success'">已支付</el-tag>
            <el-tag v-if="scope.row.status === 3" style="cursor: pointer" :type="''">已核销</el-tag>
            <el-tag v-if="scope.row.status === 4" style="cursor: pointer" :type="'success'">已评价</el-tag>
            <el-tag v-if="scope.row.status === 5" style="cursor: pointer" :type="''">订单取消</el-tag>
            <el-tag v-if="scope.row.status === 6" style="cursor: pointer" :type="''">已申请退货</el-tag>
            <el-tag v-if="scope.row.status === 7" style="cursor: pointer" :type="''">同意退货</el-tag>
            <el-tag v-if="scope.row.status === 8" style="cursor: pointer" :type="''">退货完成</el-tag>
            <el-tag v-if="scope.row.status === 9" style="cursor: pointer" :type="''">拒绝退货</el-tag>
            <el-tag v-if="scope.row.status === 10" style="cursor: pointer" :type="'success'">已完成</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-s-goods">
            <router-link :to="'/orders/info?orderId=' + scope.row.id+'&from=mer'" class="link-type">
              订单详情
            </router-link>
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getOrderList" />

  </div>
</template>

<script>
import { listByFenrun, } from "@/api/module/product/order";
import { listPropertyNoPage } from "@/api/module/property/property";
import { listAllEstate } from "@/api/module/estate/estate";

import { listByUserId } from "@/api/module/mer/mer";
import CountTo from 'vue-count-to';
import singlePic from '@/components/SingleMaterial';

export default {
  name: "Property",
  components: {
    singlePic, CountTo,
    AreaOptions:() => import('@/components/AreaOptions'),
  },
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      dateRange:[],
      // 总条数
      total: 0,
      // 物业公司表格数据
      orderList: [],
      //物业公司列表
      propertyListOptions:[],
      //小区列表
      estateListOptions:[],
      merListOptions:[],
      // 弹出层标题
      title: "",
      fenRun: 0,
      orderMoneyAll:0,
      otherDate:{},
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        merId:undefined,
        propertyId:undefined,
        estateId:undefined,
        beginDate:undefined,
        endDate:undefined
      },
      // 表单参数
      form: {},
      userType:undefined,
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getOrderList();
    // this.getPropertyList();
    // this.getEstateList();
    this.getMerListByMyUserId();
  },
  methods: {
    /** 查询物业公司列表 */
    getOrderList() {
      this.loading = true;
      listByFenrun(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.user = response.otherData.userType;
        // this.orderMoneyAll = response.otherData.orderMoneyAll;
        // this.fenRun = response.otherData.fenRun;
        this.loading = false;
        this.otherDate = response.otherData;
      });
    },
    getPropertyList() {
      listPropertyNoPage().then(response => {
        this.propertyListOptions = response.data;
      });
    },
    getMerListByMyUserId() {
      listByUserId({}).then(response => {
        this.merListOptions = response.data;
      });
    },
    getEstateList() {
      listAllEstate().then(response => {
        this.estateListOptions = response.data;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length!==1;
      this.multiple = !selection.length
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      console.log('dateRange',this.dateRange);
      if(this.dateRange !=undefined && this.dateRange.length === 2){
        this.queryParams.beginDate = this.dateRange[0];
        this.queryParams.endDate = this.dateRange[1];
      }
      this.getOrderList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    orderDetail(row){

    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .panel-group {
    margin-top: 10px;
    .card-panel-col{
      margin-bottom: 10px;
    }
    .card-panel {
      height: 108px;
      font-size: 12px;
      position: relative;
      overflow: hidden;
      cursor: pointer;
      color: #666;
      background: #fff;
      box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
      border-color: rgba(0, 0, 0, .05);



      .icon-people {
        color: #40c9c6;
      }
      .icon-message {
        color: #36a3f7;
      }
      .icon-money {
        color: #f4516c;
      }
      .icon-shopping {
        color: #34bfa3
      }
      .card-panel-icon-wrapper {
        float: left;
        margin: 14px 0 0 14px;
        padding: 16px;
        transition: all 0.38s ease-out;
        border-radius: 6px;
      }
      .card-panel-icon {
        float: left;
        font-size: 48px;
      }
      .card-panel-description {
        float: right;
        font-weight: bold;
        margin: 26px;
        color:white;
        /*margin-left: 0px;*/
        .card-panel-text {
          line-height: 18px;
          color: rgba(0, 0, 0, 0.45);
          font-size: 16px;
          margin-bottom: 12px;
        }
        .card-panel-num {
          font-size: 20px;
        }
      }
    }
  }
</style>
